using System;
using System.Collections.Generic;
using System.Data;
using Sixeyed.CodeGeneration.Metadata.Interfaces;

namespace Sixeyed.CodeGeneration.Metadata.Database
{
    /// <summary>
    /// Represents a database metadata source
    /// </summary>
    public interface IDatabaseSource : IDisposable, IMetadataSource
    {
        /// <summary>
        /// Connection string for database - used as source Uri
        /// </summary>
        string ConnectionString { get; set;}

        /// <summary>
        /// Executes given SQL against the database
        /// </summary>
        /// <param name="commandText">SQL command to execute</param>
        /// <returns>Populated data reader</returns>
        IDataReader ExecuteReader(string commandText);

        /// <summary>
        /// Returns a list of available item names
        /// </summary>
        /// <param name="itemType">Type of item to list</param>
        /// <returns>List of item names</returns>
        List<string> GetItemNames(DatabaseItemType itemType);

        /// <summary>
        /// Retruns a db command for retrieving a metadata item
        /// </summary>
        /// <param name="itemType">Type of item</param>
        /// <param name="itemKey">Item identifier</param>
        /// <returns>Db command</returns>
        IDbCommand GetItemCommand(DatabaseItemType itemType, string itemKey);

        /// <summary>
        /// Returns data from executing the given command
        /// </summary>
        /// <param name="command">Db command to execute</param>
        /// <returns>Populated data set</returns>
        DataSet GetData(IDbCommand command);

        /// <summary>
        /// Returns SQL schema from executing the given command
        /// </summary>
        /// <param name="command">Db command to execute</param>
        /// <returns>List of data tables representing schema</returns>
        List<DataTable> GetSchema(IDbCommand command);
    }
}
